<%--
  Created by IntelliJ IDEA.
  User: cx
  Date: 2019/9/6
  Time: 13:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>管理员列表</title>
    <link type="text/css" rel="stylesheet" href="../layui/css/layui.css">
    <script type="text/javascript" src="../layui/layui.js"></script>
    <script type="text/javascript" src="../js/jquery-1.12.4.js"></script>
    <script type="text/javascript">
        layui.use(["table","form","layer"],function () {
            var table=layui.table;
            var form=layui.form;
            var layer=layui.layer;
            table.render({
                elem:"#myTable",
                title:"角色列表",
                url:"${pageContext.request.contextPath}/role/selectAllRole",
                page:true,
                cols:[[
                    {checkbox:true},
                    {field:"roleId",title:"角色编号"},
                    {field:"roleName",title:"角色名字"},
                    {field:"操作",templet:"#cz"}
                ]]
            })
        })
        /*function  search() {
            var guruName=$("#guruName").val();
            layui.use(["table","form","layer"],function () {
                var table = layui.table;
                table.reload("myTable",{
                    where:{"guruName":guruName}
                });
            })
        }*/
        function add() {
            $("#did").val(0);
            $("#addSubMit").show();
            $("#updateSubMit").hide();
            layui.use("layer",function () {
                var layer=layui.layer;
                layer.open({
                    title:"添加角色",
                    content:$("#addForm"),
                    type:1
                })
            })
        }
        layui.use(["table","form","layer"],function () {
            var table=layui.table;
            var form=layui.form;
            var layer=layui.layer;
            form.on("submit(adds)",function (data) {
                $.ajax({
                    url:"${pageContext.request.contextPath}/admin/insertAdmin",
                    data:data.field,
                    type:"post",
                    success:function (data) {
                        layer.closeAll("page");
                        if(data.isAdd){
                            layer.alert("添加成功",{time:3000})
                        }else {
                            layer.alert("添加失败",{time:3000})
                        }
                        table.reload("myTable");
                    }
                })
                return false;
            })
        })
        /*function deleteD(guruId) {
            layui.use(["table","form","layer"],function () {
                var table=layui.table;
                var form=layui.form;
                var layer=layui.layer;
                layer.confirm("确定删除该条数据吗？",function (data) {
                    $.ajax({
                        url:"${pageContext.request.contextPath}/deleteGuru",
                        type:"post",
                        data:"guruId="+guruId,
                        success:function (data) {
                            if(data.isDelete){
                                layer.alert("删除成功",{time:2000})
                            }else {
                                layer.alert("删除失败",{time:2000})
                            }
                            table.reload("myTable");
                        }
                    })
                })
            })
        }*/
        /*删除开始*/
        function deleteD(id) {
            layui.use(["table","form","layer"],function () {
                var table=layui.table;
                var form=layui.form;
                var layer=layui.layer;
                layer.confirm("确定删除该条数据吗？",function (data) {
                    $.ajax({
                        url:"${pageContext.request.contextPath}/admin/deleteAdmin",
                        type:"post",
                        data:"id="+id,
                        success:function (data) {
                            if(data.isDelete){
                                layer.alert("删除成功",{time:2000})
                            }else {
                                layer.alert("删除失败",{time:2000})
                            }
                            table.reload("myTable");
                        }
                    })
                })
            })
        }
        /*删除结束*/
        function showOne(id) {
            $.ajax({
                url:"${pageContext.request.contextPath}/admin/selectById",
                data:"id="+id,
                type:"post",
                success:function (data) {
                    $("#id").val(data.id);
                    $("#userName").val(data.userName);
                    $("#password").val(data.password);

                }
            })
            $("#addSubMit").hide();
            $("#updateSubMit").show();
            layui.use("layer",function () {
                var layer = layui.layer;
                layer.open({
                    title: "修改管理员",
                    content: $("#addForm"),
                    type: 1,
                    maxmin: true
                })
            })
            layui.use(["table","form","layer"],function () {
                var table=layui.table;
                var form=layui.form;
                var layer=layui.layer;
                form.on("submit(update)",function (data) {
                    $.ajax({
                        url:"${pageContext.request.contextPath}/admin/updataAdmin",
                        data:data.field,
                        success:function (data) {
                            layer.closeAll("page");
                            if(data.isUpdate){
                                layer.alert("修改成功",{time:2000});
                            }else {
                                layer.alert("修改失败",{time:2000});
                            }
                            table.reload("myTable");
                        }
                    })
                })
            })
        }
        /*function deleteAlls() {
            layui.use(["layer","form","table"],function () {
                var table=layui.table;
                var checkStatus=table.checkStatus("myTable");
                var data=checkStatus.data;
                if(data.length==0){
                    layer.alert("请选择要删除的数据");
                }else {
                    layer.confirm("确定要删除的数据",function (index) {
                        var ids=new Array(data.length);
                        for(var i=0;i<ids.length;i++){
                            ids[i]=data[i].departmentId;
                            $.ajax({
                                url:"/HospitalManageMentSystem/multiDelete",
                                data:"ids="+ids,
                                success:function (data) {
                                    layer.close(index);
                                    layer.alert(data.isMuitlDelete,{time:2000});
                                    table.reload("myTable");
                                }
                            })
                        }
                    })
                }
            })
        }
*/
    </script>

    <script id="guruStatusTemplet" type="text/html">
        {{#  if(d.guruStatus == 0){ }}
        正常
        {{#  } else { }}
        冻结
        {{#  } }}
    </script>
    <style>
        .layui-table-cell{
            height:36px;
            line-height: 36px;
        }
    </style>
</head>
<body>
<div id="cz" style="display:none;">
    <button class="layui-btn layui-btn-normal" onclick="showOne('{{d.id}}')">修改</button>
    <button class="layui-btn layui-btn-danger" onclick="deleteD('{{d.id}}')">删除</button>
</div>
<button type="button" class="layui-btn" onclick="add()">
    <i class="layui-icon">&#xe608;</i> 添加管理员
</button>
<button type="button" class="layui-btn layui-btn-danger" onclick="deleteAlls()">
    <i class="layui-icon">&#xe640;</i> 批量删除
</button>
<%--<div class="layui-inline" id="search">
    <label class="layui-form-label">查询名称</label>
    <div class="layui-input-inline" style="width: 200px;">
        <input type="text" class="layui-input" id="guruName">
    </div>
    <div class="layui-input-inline" style="width: 100px;">
        <button type="button" class="layui-btn layui-btn-normal" onclick="search()">
            <i class="layui-icon layui-icon-search"></i> 搜索
        </button>
    </div>
</div>--%>
<table id="myTable"></table>
<form class="layui-form" style="display: none" id="addForm">
    <div class="layui-form-item">
        <label class="layui-form-label">管理员编号</label>
        <div class="layui-input-block">
            <input  id="id" value="0" name="id" autocomplete="off" class="layui-input" readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">管理员名字</label>
        <div class="layui-input-block">
            <input type="text" name="userName" id="userName" required  lay-verify="required|userName" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">管理员密码</label>
        <div class="layui-input-inline">
            <input type="text" name="password" id="password" required lay-verify="required|password"  autocomplete="off" class="layui-input">
        </div>
    </div>



    <div class="layui-form-item">
        <button  type="button" lay-submit lay-filter="adds" class="layui-btn" id="addSubMit">添加</button>
        <button  type="button" lay-submit lay-filter="update" class="layui-btn" id="updateSubMit">修改</button>

        <button  type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>



<%--删除表单--%>
<form class="layui-form" style="display: none" id="deleteForm">
    <div class="layui-form-item">
        <label class="layui-form-label">上师编号</label>
        <div class="layui-input-block">
            <input  id="guruId2"  name="guruId" autocomplete="off" class="layui-input" readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上师状态</label>
        <div class="layui-input-inline">
            <input type="text" name="guruStatus" id="guruStatus2" required lay-verify="required|guruStatus" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <button  type="button" lay-submit lay-filter="update" class="layui-btn" id="deleteSubMit">删除</button>
        <button  type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>



</body>
</html>
